#ifndef WORKPIECEE575_H
#define WORKPIECEE575_H
#include "../MeasureWorkpiece.h"

#include "ms575_algbackdatum.h"
#include "ms575_algbackdowncircle.h"
#include "ms575_algbackleftcircle.h"
#include "ms575_algbackrightcircle.h"
#include "ms575_algbacks1s2rectedge.h"
#include "ms575_algbackss1ss2smallcircle.h"
#include "ms575_algbase.h"
#include "ms575_algbackdowncircle.h"
#include "ms575_algbackleftcircle.h"
#include "ms575_algbackrightcircle.h"
#include "ms575_algbacks1s2rectedge.h"
#include "ms575_algfrontse3se4se5se6se7se8edgeouter.h"
#include "ms575_algfrontss3toss8smallcircle.h"
#include "ms575_algbacks3s4ldmeasure.h"
#include "ms575_edgedetect.h"
#include "ms575_alghighse1se9edgeouter.h"
#include "ms575_algbacks4s5s6ldmeasure.h"

using namespace MeasurE575;

class WorkpieceE575 : public MeasureWorkpiece
{
public:
    WorkpieceE575();
    ~WorkpieceE575();

    bool SetTemplatePath(const std::string &path);
    bool SetStandardVal(const std::map<std::string, MeasureItemStandardVal> &standardValMap);
    void SetWorkpieceInfo(const std::string &modeName,
                          const std::string &workpieceType = "");
    void CacheData(const cv::Mat &image     ,
                   const QPoint &datumOffset,
                   int workpieceId          ,
                   int pictureId            ,
                   int channelId            ,
                   int fixtureId);

    void ProcessData();
    bool GetDatumPixelDistance(const QImage &img,
                               int fixtureId,
                               QMap<QString, float> &pixelDistance);
    void InitThread();
    void ExitThread();

private:
    void CorrectThreeD(std::map<std::string, float> &measRes, int fixtureId);
    float CalPosition(std::map<std::string, float> &measRes,
                      std::string strX, std::string strY);

private:
    QMap<int, WorkpieceInfo>                    m_workpieceMap      ;
    std::mutex                                  m_ioMutex;
    std::vector<std::thread>                    m_threadPool;
    bool                                        m_initThreadFinished_;          // 线程初始化完成标志
    bool                                        m_isSetPathFlag        ;

public:
    WorkpieceBuff                               m_workpieceBuff;
    std::atomic<bool>                           m_threadStopFlag    ;
};

#endif // WORKPIECEE575_H
